#include <stdio.h>

void reverse(int a[], int left, int right, int k) {
    int temp;
    for (int i = left, j = right; i < left + k && i < j; ++i, --j) {
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}

void moveP(int a[], int n, int p) {
    reverse(a, 0, p - 1, p);
    reverse(a, p, n - 1, n - p);
    reverse(a, 0, n - 1, p);
}

int main() {
    int a[5] = {1, 2, 3, 4, 5};
    // reverse(a, 0, 4, 2);
    moveP(a, 5, 3);
    for (int loop = 0; loop < 5; loop++) {
        printf("%d ", a[loop]);
    }
    return 0;
}

